<?php
/**
 * 掌上客小程序商城模块微站定义
 * 
 * @author zskcms
 * @url 
 */
defined('IN_IA') or exit('Access Denied');
ini_set("display_errors", "OFF"); 

!defined('ZSK_MODULE') && define('ZSK_MODULE','zsk_browser');
!defined('ZSK') && define('ZSK',IA_ROOT.'/addons/zsk_browser');
!defined('CORE_WEB') && define('CORE_WEB',ZSK.'/core/web');
!defined('CORE_MOB') && define('CORE_MOB',ZSK.'/core/mob');
!defined('CORE_APP') && define('CORE_APP',ZSK.'/core/wxapp');
!defined('WEB') && define('WEB','../addons/zsk_browser/template/web');
!defined('PUB') && define('PUB','../addons/zsk_browser/template/public');
if (!function_exists('Model')) {
	function Model($name) {
		$model = new ZskxdswModel($name);
		return $model;
	} 
} 
function WebUrl($do,$param=array()){
	 $gets=$_GET;
	 $module0=strlen($gets['m'])>0?$gets['m']:ZSK_MODULE;
	 $url0=url('site/entry/'.$do,array("m"=>$module0));
	 $url0.="&version_id=".intval($gets['version_id']);
	 if(count($param)){
	 	 foreach ($param as $key => $val) {
	 		$url0.="&$key=$val";
		 }
	 } 
	 return  $url0;
}
require_once ZSK."/libs/model.class.php"; 
class Zsk_browserModuleSite extends WeModuleSite {
	 
	public function doWebHome(){
		global $_W,$_GPC;
		$model=Model("home");
		$uniacid=intval($_W['uniacid']); 
		$func=$_GPC['act'];
		if(strlen($func)<1){
			$func="edit";
		} 
		if($func=="edit"){  
			$home=$model->where("uniacid=$uniacid")->get("*");
			include $this->template("web/home-edit");
		} 
		else if($func=="save"){
			$home=$model->where("uniacid=$uniacid")->get("*");
			$home1=array(
				"bar_color"=>trim($_POST['bar_color']),
				"url"=>urlencode($_POST['url']),
				"bar_bgcolor"=>trim($_POST['bar_bgcolor']),
				"share"=>trim($_POST['share']),

			);
			$hid=intval($home['id']);
			if($hid>0){ 
				$res=$model->where("uniacid=$uniacid")->save($home1);
				 message("保存成功",$this->createWebUrl("home"));	 
				 
			}else{
				 
				$home1['uniacid']=$uniacid;
				$model=Model("home");
				$res=$model->add($home1);  
				if($res){
					message("保存成功",$this->createWebUrl("home"));
				}else{
					message("保存失败");
				}
				 
			}
		} 

	}
	 
}